mui.init();
//获取本地信息
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var preDeposit, Grade, status; //公共变量
window.onload = function() {
	mui.plusReady(function() {
		var self = plus.webview.currentWebview();
		preDeposit = self.preDeposit;
		silverList(1)
		
	});
}

mui('body').on('tap', '.mui-control-item', function() {
//	window.top.location.href = this.href;
	$(this).addClass("mui-active").siblings().removeClass('mui-active');
	var statusText = $(this).attr('data-status');
	silverList(statusText)
	
});

// api/user/silverInfo
function silverList(type){
	if(type==1){
		mui.ajax(user_url +'/api/Silver/getSilverTreasure',{
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success:function(data){
				console.log('银宝明细');
				console.log(JSON.stringify(data))
				if(data.code == 10000) {
					var html = ""
					var hotShop = data.resp;
					for(var i = 0; i < hotShop.length; i++) {
						html += '<li class="mui-table-view-cell advance_record_li" onclick="detailPage('+hotShop[i].id+')">'
						html += '<a class="mui-pull-left">'
						html += ''+hotShop[i].text+''
						html += '<p>'+hotShop[i].create_time+'</p>'
						html += '</a>'
						if(hotShop[i].sign==2){
							html += '<span class="mui-pull-right">-￥<i>'+hotShop[i].number+'</i></span>'
						}
						else{
							html += '<span class="mui-pull-right">+￥<i>'+hotShop[i].number+'</i></span>'
						}
						
						html += '</li>';
					}
					$(".advance_record_list").html(html);
				}
				else{
					mui.alert(data.msg);
				}
			}
		})
	}
	else if(type==2){
		mui.ajax(user_url +'/api/Silver/getConvertSilverInfo',{
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success:function(data){
				console.log('兑换明细');
				console.log(JSON.stringify(data))
				if(data.code == 10000) {
					var html = ""
					var hotShop = data.resp;
					for(var i = 0; i < hotShop.length; i++) {
						html += '<li class="mui-table-view-cell advance_record_li" >'
						html += '<a class="mui-pull-left">'
						html += ''+hotShop[i].explain+''
						html += '<p>'+hotShop[i].createtime+'</p>'
						html += '</a>'
						if(hotShop[i].sign==2){
							html += '<span class="mui-pull-right">-￥<i>'+hotShop[i].convert_silver+'</i></span>'
						}
						else{
							html += '<span class="mui-pull-right">+￥<i>'+hotShop[i].convert_silver+'</i></span>'
						}						
						html += '</li>';
					}
					$(".advance_record_list").html(html);
				}
				else{
					mui.alert(data.msg);
				}
			}
		})
	}
	else if(type==3){
		mui.ajax(user_url +'/api/Silver/getConsumeCilverInfo',{
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success:function(data){
				console.log('消费明细');
				console.log(JSON.stringify(data))
				if(data.code == 10000) {
					var html = ""
					var hotShop = data.resp;
					for(var i = 0; i < hotShop.length; i++) {
						html += '<li class="mui-table-view-cell advance_record_li" >'
						html += '<a class="mui-pull-left">'
						html += ''+hotShop[i].text+''
						html += '<p>'+hotShop[i].create_time+'</p>'
						html += '</a>'
						if(hotShop[i].sign==2){
							html += '<span class="mui-pull-right">-￥<i>'+hotShop[i].number+'</i></span>'
						}
						else{
							html += '<span class="mui-pull-right">+￥<i>'+hotShop[i].number+'</i></span>'
						}						
						html += '</li>';
					}
					$(".advance_record_list").html(html);
				}
				else{
					mui.alert(data.msg);
				}
			}
		})
	}
}
//返回user页面
$(document).on('tap', '.go_user', function() {
	window.top.location.href = "../my/yinbao_center.html";
})
//充值
//document.getElementById("imprest_recharge").addEventListener("tap", function() {
////	if(status == 2) {
////		mui.toast('账户已被限制，请联系平台。');
////		return;
////	}
//	mui.openWindow({
//		url: '../my/cash_recha.html',
//		createNew: true,
//	});
//});
//明细
//document.getElementById("detail_page").addEventListener("tap", function() {
//	//cash_record.html
//	mui.openWindow({
//		url: '../my/yinbao_record.html',
//		createNew: true,
//	});
//});
//提现
//document.getElementById("put_forward").addEventListener("tap", function() {
//	mui.openWindow({
//		url: "../my/cash_advance.html",
//		id: "cash_advance"
//	});
//});

//调用userinfo接口判断是否是商家
//function userinfo() {
//	mui.ajax(user_url + '/api/userinfo', { //查询用户信息接口
//		data: {
//			"phone": my_phone,
//			"sign": "string",
//			"user_id": user_id
//		},
//		dataType: 'json', //服务器返回json格式数据
//		type: 'post', //HTTP请求类型
//		timeout: 10000, //超时时间设置为10秒；
//		headers: {
//			'Content-Type': 'application/json'
//		},
//		success: function(data) {
//			if(data.code == 10000) {
//				Grade = data.resp.level; //个人等级
//				status = data.resp.status; //账户状态
//			}
//		},
//		error: function(xhr, type, errorThrown) { //异常处理；
//			console.log(type);
//		}
//	});
//}